use std::collections::HashMap;

struct Solution {}

fn main() {}

impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        let mut value_idx_map: HashMap<i32, Vec<i32>> = HashMap::new();
        for idx in 0..nums.len() {
            if value_idx_map.contains_key(&nums[idx]) {
                value_idx_map.get_mut(&nums[idx]).unwrap().push(idx as i32);
            }
            else {
                value_idx_map.insert(nums[idx], vec![idx as i32]);
            }
        }
        for idx in 0..nums.len() {
            let target_ele = target - nums[idx];
            if target_ele == nums[idx] {
                if value_idx_map[&target_ele].len() >= 2 {
                    return vec![idx as i32, (value_idx_map.get(&target_ele).unwrap())[1]];
                }
                continue;
            }
            if value_idx_map.contains_key(&target_ele) {
                return vec![idx as i32, (value_idx_map.get(&target_ele).unwrap())[0]];
            }
        }
        vec![]
    }
}